/*
 * @Author: jhw jiaxianshengye@gmail.com
 * @LastEditTime: 2025-08-01 11:28:12
 * @LastEditors: jhw
 * @Description: 文件描述
 */
import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
import 'virtual:windi.css'
import * as Sentry from '@sentry/vue'
import VueEsignPlus from 'vue-esignplus'

// 最先执行的性能监控
if (typeof window !== 'undefined') {
  // 捕获已发生的绘制事件
  const paintEntries = performance.getEntriesByType('paint')
  paintEntries.forEach((entry) => {
    console.log(`[Initial Paint] ${entry.name}: ${entry.startTime.toFixed(2)}ms`)
  })

  // 设置观察者捕获后续事件
  const perfObserver = new PerformanceObserver((list) => {
    list.getEntries().forEach((entry) => {
      console.log(`[Performance] ${entry.name}: ${entry.startTime.toFixed(2)}ms`)
    })
  })

  // 监控多种性能指标
  perfObserver.observe({
    entryTypes: [
      'paint', // 绘制时间
      'largest-contentful-paint', // LCP
      'first-input', // FID
      'layout-shift', // CLS
      'navigation', // 页面导航
    ],
  })
}

const app = createApp(App)

if (import.meta.env.MODE === 'production') {
  Sentry.init({
    app,
    dsn: 'https://65c4da35617661edfa43eb9997ea62af@o4509324793151488.ingest.us.sentry.io/4509756410626048',
    // Setting this option to true will send default PII data to Sentry.
    // For example, automatic IP address collection on events
    integrations: [
      // Or omit `router` if you're not using vue-router
      Sentry.browserTracingIntegration({
        // 配置路由
        router: router,
      }),
    ],
    tracesSampleRate: 1, // 设置采样率
  })
}

app.use(createPinia())
app.use(router)
app.use(VueEsignPlus)

app.mount('#app')
